package com.enseirb.bdxmap.dao.parser;

import org.json.simple.JSONObject;

import com.enseirb.bdxmap.dao.dto.RestroomMarkerDTO;

public class RestroomMarkerParser extends AbstractMarkerParser<RestroomMarkerDTO> {
	private static final String JSON_KEY_OPTIONS = "options";
	private static final String JSON_KEY_TYPOLOGY = "typologie";
	private static final String JSON_KEY_NAME = "nom";
	private static final String JSON_KEY_LAT = "y_lat";
	private static final String JSON_KEY_LONG = "x_long";
	private static final String JSON_KEY_ID = "entityid";
	private static final String DEFAULT_NAME = "Toilettes sans nom";
	
	public RestroomMarkerParser() {
		super();
		json_key_id = JSON_KEY_ID;
		json_key_long = JSON_KEY_LONG;
		json_key_lat = JSON_KEY_LAT;
		json_key_name = JSON_KEY_NAME;
		default_marker_name = DEFAULT_NAME;
	}
	
	@Override
	public RestroomMarkerDTO newServiceDTO() {
		return new RestroomMarkerDTO();
	}

	@Override
	protected RestroomMarkerDTO getCustomFieldsFromJson(
			RestroomMarkerDTO restroomDTO, JSONObject restroomJson) {
		restroomDTO.typology = getTypologyFromJson(restroomJson);
		restroomDTO.options = getOptionsFromJson(restroomJson);
		return restroomDTO;
	}

	private String getTypologyFromJson(JSONObject restroomJson) {
		if(restroomJson.containsKey(JSON_KEY_TYPOLOGY)) {
			return restroomJson.get(JSON_KEY_TYPOLOGY).toString();
		} else {
			return "";
		}
	}

	private String getOptionsFromJson(JSONObject restroomJson) {
		if(restroomJson.containsKey(JSON_KEY_OPTIONS)) {
			return restroomJson.get(JSON_KEY_OPTIONS).toString();
		} else {
			return "";
		}
	}
}
